package com.example.moonshine.redzxingtwo.Util;

import com.example.moonshine.redzxingtwo.Data.ReturnStatusData;
import com.google.gson.Gson;

import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by moonshine on 2018/4/11.
 */

public class SpostHttpMap {
    public String posthttpmap(String Sresult,String aluminumcode,String path) {
        //okhttp Post请求传输Json数据
        String SpostStatus = null;
        //将接收到的JSON数据放到实体类里
        Gson gson =new Gson();
        OkHttpClient client = new OkHttpClient();
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        FormBody body = new FormBody.Builder()
                .add("orderId",Sresult)
                .add("aluminumCode",aluminumcode)
                .build();

        Request request = new Request.Builder()
                .url(path)
                .post(body)
                .build();
        try {
            Response response = client.newCall(request).execute();

            //获取后台传输的额status状态码
            String result = response.body().string();
            ReturnStatusData returnStatusData= gson.fromJson(result,ReturnStatusData.class);
            //定义一个参数来获取状态码
            SpostStatus = returnStatusData.getStatus();
        }catch (Exception e){
            e.printStackTrace();
        }
        return SpostStatus;
    }
}
